from sqlalchemy import INT, Column, BigInteger, String
import goodDesignImage2018Spider.dao.dbConfig as mysqlConfig

# 对象的基类
Base = mysqlConfig.get_base()
# 初始化数据库连接
engine = mysqlConfig.get_eng()
# 创建DBSession类型
DBSession = mysqlConfig.get_db_session()


class WaiMaiYuanItemOrm(Base):
    # 表名
    __tablename__ = 'waimaiyuan_item'
    # 主键id
    item_id = Column(BigInteger(), primary_key=True)
    # 名称
    item_name = Column(String(100), default='')
    # 父id
    item_parent_id = Column(BigInteger(), default=-1)
    # 备注
    item_remark = Column(String(100), default='')
    # 业务类型 0菜谱分类
    item_biz_type = Column(INT())

    # 获取菜谱一级分类
    @staticmethod
    def get_1_cp():
        session = DBSession()
        items = session.query(WaiMaiYuanItemOrm).filter(
            WaiMaiYuanItemOrm.item_parent_id == -1, WaiMaiYuanItemOrm.item_biz_type == 0)
        session.close()
        return items

    # 根据类型获取所有item
    @staticmethod
    def get_by_type(biz_type):
        session = DBSession()
        items = session.query(WaiMaiYuanItemOrm).filter(WaiMaiYuanItemOrm.item_biz_type == biz_type)
        session.close()
        return items


if __name__ == '__main__':
    WaiMaiYuanItemOrm.get_1_cp()
    WaiMaiYuanItemOrm.get_by_type(0)
